class HResult:

    # 常用的状态码
    code_type = {
        'success': 200,
        'error': 400,
        'unauthorized': 401,
        'forbidden': 403,
        'not_found': 404,
        'method_not_allowed': 405,
        'internal_server_error': 500,
    }

    def __init__(self):
        self.code = ''
        self.message = ''

    def set_code(self, code):
        self.code = code
        return self

    def set_message(self, message):
        self.message = message
        return self

    def get_result(self, c_type, message="操作成功", data=None):
        # 获取返回结果

        if c_type in self.code_type:
            self.code = self.code_type[c_type]

        if message:
            self.message = message

        return {
            'code': self.code,
            'message': self.message,
            'result': data,
        }, self.code
